package model.game;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JComponent;
import javax.swing.JFrame;

import view.DebugPanel;
import view.GamePanel;

import model.player.Player;


public class ShapeTD extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	private Board _board;
	
	
	public ShapeTD() {
		
		_initFrame();
		_initGame();
		this.setLocationRelativeTo(null);
	}
	
	
	private void _initGame() {
		
		/******
		DebugPanel debug = DebugPanel.getInstance();
		showOnFrame(debug, BorderLayout.EAST);
		/****/
		
		Player player = new Player();
		Map map = new Map();
		
		_board = new Board(player);
		_board.init(map);
		showOnFrame(_board, BorderLayout.WEST);
		
		GamePanel gamePanel = new GamePanel(player); 
		showOnFrame(gamePanel, BorderLayout.EAST);
		
		
		
		// Should not be called here. To move later in the start button click event.
		_board.start();
	}


	/**
	 * Construct the game's frame
	 */
	public void _initFrame() {
		
		WindowAdapter wa = new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		};
		this.setName("ShapeTD");
		this.setTitle("ShapeTD");
		this.addWindowListener(wa);
		this.setResizable(false);
	}
	
	
	/**
	 * Start the game. 
	 * This method initialize all panels and initialize the board with the first map found.
	 */
	public void start() {
		
	}

	
	/**
	 * Show a component of the game frame
	 * You must specify the position of the component on the frame with the second parameter.
	 * 
	 * @param component
	 * @param borderLayout
	 */
	public void showOnFrame(JComponent component, String borderLayout) {
		
		this.getContentPane().add(component, borderLayout);
		this.pack();
		this.setVisible(true);
	}
	
}
